﻿Imports System.Data.SqlClient
Imports System.Windows.Forms
Imports LINKARReport.Componet

Public Class DlgShowReport

#Region "窗体申明变量"

    Private _nMidDbConnection1 As String

    ''' <summary>
    ''' 说明：模块名      
    ''' </summary>
    ''' <remarks></remarks>
    Private _nModuleName As String

    ''' <summary>
    ''' 说明：字段对应模块名=f_columnlib.col_tablename      
    ''' </summary>
    ''' <remarks></remarks>
    Private _nColumnName As String

    ''' <summary>
    ''' 说明：数据库链接参数      
    ''' </summary>
    ''' <remarks></remarks>
    Private _nConnection1 As String
    Private _nflex As FlexGridLib
    ''' <summary>
    ''' 2019.9.1
    ''' 日志
    ''' </summary>
    Private _nstrlog As String

#End Region

#Region "窗体自定义属性"

    ''' <summary>
    ''' 2018.12.9
    ''' 中间库数据库连接
    ''' </summary>
    ''' <returns></returns>
    Public Property NMidDbConnection As String
        Get
            Return _nMidDbConnection1
        End Get
        Set
            _nMidDbConnection1 = Value
        End Set
    End Property

    ''' <summary>
    ''' 说明：模块名     
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property NModuleName As String
        Set(value As String)
            _nModuleName = value
        End Set
    End Property

    ''' <summary>
    ''' 说明：字段模块名=f_columnlib.col_tablename       
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property NColumnName As String
        Set(value As String)
            _nColumnName = value
        End Set
    End Property

    ''' <summary>
    ''' 说明：数据库链接字符串     
    ''' </summary>
    ''' <value></value>
    ''' <remarks></remarks>
    Public WriteOnly Property NConnection As String
        Set(value As String)
            _nConnection1 = value
        End Set
    End Property
    ''' <summary>
    ''' 记在数据源
    ''' 默认datatable从master,detail,group,hz
    ''' </summary>
    ''' <returns></returns>
    Public Property NDataSource As DataSet
    ''' <summary>
    ''' 2020.5.4
    ''' 应用程序路径
    ''' </summary>
    ''' <returns></returns>
    Public Property NAppPath As String
    ''' <summary>
    ''' 2021.5.23
    ''' 报表格式
    ''' </summary>
    ''' <returns></returns>
    Public Property NTabType As String = "表格"
    ''' <summary>
    ''' 2023.2.28
    ''' 新增币种
    ''' </summary>
    ''' <returns></returns>
    Public Property NMoneyType As String = "RMB"
#End Region

#Region "窗体自定义函数及事件"

    ''' <summary>
    ''' 2019.11.25
    ''' 显示报表
    ''' </summary>
    ''' <returns></returns>
    Private Function P_ShowReport() As Integer
        Dim intsuc As Integer = -2
        Try
            MsgBox("2")
            Dim introw As Integer = FG_list.RowSel
           
            If introw < 1 Then
                MsgBox("你请选择报表",, "警告")
                Return -2
                Exit Function
            End If
            MsgBox(_nConnection1)
            Dim strfilename As  String=Convert.ToString(FG_list.Rows(introw)("m_rpfilepath"))
            MsgBox(strfilename)
            strfilename = "d:\apps\linknotes\" + strfilename '报表文件名
            Dim strlog As String = $"{_nConnection1},{strfilename},{NDataSource.Tables.Count}"
            MsgBox(strlog)
            If Len(NAppPath) > 0 Then '如果指定路径 2020.5.4
                strfilename = NAppPath + Convert.ToString(FG_list.Rows(introw)("m_rpfilepath"))
            End If

            Dim obj As New DlgReportView
            With obj
                .NConnection = _nConnection1
                .NMidDbConnection = _nMidDbConnection1
                .NDataSource = NDataSource
                .NReportFileName = strfilename '加载的文件名
                .WindowState = FormWindowState.Maximized
                .LoadReport()
                .ShowDialog()

                .Close()
            End With
            intsuc = 1
        Catch ex As Exception
            MsgBox(ex.Message, , "错误")
        End Try
        Return intsuc
    End Function

#End Region

    Public Sub New()

        ' 此调用是设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。
        _nflex = New FlexGridLib(FG_list)
        _nflex.SelectTheme(Theme.Office10Blue)
        NAppPath = ""
    End Sub

    Private Sub DlgShowReport_Shown(sender As Object, e As EventArgs) Handles Me.Shown
        '2023.2.28 ,读取moneytype币种信息，语句更改
        'f_sqllib.col_group=readreport改成readreportmoneyType
        Dim strsqlcmd As String = MClsConfig.SqlLib("myreport", "selectReportMoneyType", _nConnection1)

        Dim dbpara() As SqlParameter = {New SqlParameter("@ModName", _nModuleName),
                                        New SqlParameter("@moneyType", NMoneyType),
                                                    New SqlParameter("@tabtype", NTabType)}
        Dim dtReportData As New DataTable
        dtReportData = MClsConfig.F_GetDataTable(strsqlcmd, CommandType.Text, dbpara, _nConnection1)

        _nflex.BindData("myreport", dtReportData, _nConnection1)
        '//显示报表名称
        If dtReportData.Rows.Count > 0 Then
            lblmodname.Text = Convert.ToString(dtReportData.Rows(0)("m_name")) '模块标题名称
        End If
    End Sub

    Private Sub cmd_enter_Click(sender As Object, e As EventArgs) Handles cmd_enter.Click
        MsgBox("1")
      '  P_ShowReport()
        Try
            MsgBox("2")
            Dim introw As Integer = FG_list.RowSel

            MsgBox(_nConnection1)
            Dim strfilename As  String=Convert.ToString(FG_list.Rows(introw)("m_rpfilepath"))
            MsgBox(strfilename)
            strfilename = "d:\apps\linknotes\" + strfilename '报表文件名
            Dim strlog As String = $"{_nConnection1},{strfilename},{NDataSource.Tables.Count}"
            MsgBox(strlog)
            If Len(NAppPath) > 0 Then '如果指定路径 2020.5.4
                strfilename = NAppPath + Convert.ToString(FG_list.Rows(introw)("m_rpfilepath"))
            End If

            Dim obj As New DlgReportView
            With obj
                .NConnection = _nConnection1
                .NMidDbConnection = _nMidDbConnection1
                .NDataSource = NDataSource
                .NReportFileName = strfilename '加载的文件名
                .WindowState = FormWindowState.Maximized
                .LoadReport()
                .ShowDialog()

                .Close()
            End With

        Catch ex As Exception
            MsgBox(ex.Message, , "错误")
        End Try
    End Sub

    Private Sub cmd_cancel_Click(sender As Object, e As EventArgs) Handles cmd_cancel.Click
        Me.Dispose()
    End Sub

    Private Sub cmd_enter1_Click(sender As Object, e As EventArgs) Handles cmd_enter1.Click
     
        '  P_ShowReport()
        Try

            Dim introw As Integer = FG_list.RowSel
            Dim strfilename As String=System.Environment.CurrentDirectory+Convert.ToString(FG_list.Rows(introw)("m_rpfilepath")) ‘报表文件名
            If Len(NAppPath) > 0 Then '如果指定路径 2020.5.4
                strfilename = NAppPath + Convert.ToString(FG_list.Rows(introw)("m_rpfilepath"))
            End If

            Dim obj As New DlgReportView
            With obj
                .NConnection = _nConnection1
                .NMidDbConnection = _nMidDbConnection1
                .NDataSource = NDataSource
                .NReportFileName = strfilename '加载的文件名
                .WindowState = FormWindowState.Maximized
                .LoadReport()
                .ShowDialog()

                .Close()
            End With

        Catch ex As Exception
            MsgBox(ex.Message, , "错误")
        End Try
    End Sub

    Private Sub cmd_cancel1_Click(sender As Object, e As EventArgs) Handles cmd_cancel1.Click
        Me.Dispose()
    End Sub
End Class